<table class="user">
    <tr class="head" height="28px">
        <th width="50px">STT</th>
        <th width="220px">Email</th>
        <th width="200px">Họ tên</th>
        <th width="100px">Nhóm</th>
        <th width="120px">Ngày đăng ký</th>
        <th width="120px">Đổi mật khẩu</th>
        <th width="80px">Sửa</th>
        <th width="80px">Xóa</th>
    </tr>
    <?php 
        $count = 1;
        foreach ($this->users as $item_user){?>
        <tr>
            <td style="text-align: center"><?php echo $count?></td>
            <td><p><?php echo $item_user['user_email']?></p></td>
            <td><p><?php echo $item_user['user_fullname']?><p></td>
            <td style="text-align: center"><?php echo $item_user['user_role']?></td>
            <td style="text-align: center"><?php $date = date_create($item_user['user_datecreate']); echo date_format($date, 'd-m-Y')?></td>
            <td style="text-align: center">
                <a class="change-pass" href="<?php echo $this->baseUrl('admin/user/changpass/id/') .$item_user['user_id']?>" title="Đổi mật khẩu">
                <img src="<?php echo $this->baseUrl('admin/images/change_pass.ico')?>" alt="pass"/></a> 
            </td>
            <td style="text-align: center">
                <a class="edit" href="" title="Sửa">
                    <img alt="edit" src="<?php echo $this->baseUrl('admin/images/edit.ico')?>"/>
                </a>
            </td>
            <td style="text-align: center">
                <a class="del" href="<?php echo $this->baseUrl('admin/user/delete/id/') .$item_user['user_id']?>" title="Xóa">
                    <img alt="del" src="<?php echo $this->baseUrl('admin/images/remove.ico')?>">
                </a>
            </td>
        </tr>
    <?php $count++; }?>
</table>
    <div class="dialog"></div>
    <?php if($this->users->Count() > 1) {?>                
        <div id="paginator">
             <?php echo $this->paginationControl($this->users, 'Sliding', 'index/pagination.phtml')?>
        </div>
    <?php }?>

<div id="dialog-form" title="Đổi mật khẩu" class="hidden">
    <p class="validateTips"></p>
    <form>
        
            <label for="password">Mật khẩu muốn đổi</label>
            <input name="password" type="password" id="password" class="text ui-widget-content ui-corner-all"/>
            <label for="repassword">Xác nhận mật khẩu</label>
            <input name="repassword" id="repassword" type="password" class="text ui-widget-content ui-corner-all"/>
        
    </form>
</div>    
    
<script>
//delete user
$(document).ready(function(){
    $("table.user a.del").click(function(){
        var _this = $(this);
        $(".dialog").html("<div>Bạn có chắc muốn xóa người dùng này?</div").dialog({
            resizable: false,
            modal: true,
            buttons: {
                "Có":function(){
                    var link = _this.attr("href");
                    $.ajax({
                        url: link,
                        });
                    _this.parent().parent().remove();
                    $(this).dialog("close");
                    },
                "Không":function(){
                    $(this).dialog("close");
                    }
                }
            });
        return false;
        });
    	
});

//change password user
$(function(){
	var password = $("#password");
	var repassword = $("#repassword");
	var allFields = $([]).add(password).add(repassword);
	var tips = $( ".validateTips" );

	function check(pass, repass){
	    if(pass.val() == repass.val())
		    return true;
	    else if($.trim(pass.val()) == ''){
	    	pass.addClass( "ui-state-error" );	    	
		    updateTips('Không được bỏ trống');
		    return false;
		    }
	    else{
		    repass.addClass( "ui-state-error" );
		    updateTips('Mật khẩu nhập lại không đúng');
	        return false;
	    }
	}
	function updateTips( t ) {
		tips
			.text( t )
			.addClass( "ui-state-highlight" );
		setTimeout(function() {
			tips.removeClass( "ui-state-highlight", 1500 );
		}, 500 );
	}
	
	$("table.user a.change-pass").click(function(){
	    var _this = $(this);
	    $("#dialog-form").dialog({
		    resizable: false,
		    width: 350,
		    height: 300,
		    modal: true,
		    buttons :{
			    "Đổi mật khẩu": function(){
				    var valid = true;
				    allFields.removeClass("ui-state-error");
				    valid = check(password, repassword);
				    if(valid){
				        var link = _this.attr("href");
				        rdata = {"pass": password.val()};
					    $.ajax({
						    url: link,
						    data: rdata,
						    });
					    $(this).dialog("close");
					    }
				    },
				 "Thoát": function(){
					 $(this).dialog("close");
					 }
			    },
			   close: function() {
					allFields.val( "" ).removeClass( "ui-state-error" );
					updateTips("");
			   }
			});
		return false;
	});
		});
	

//color row of table
$(document).ready(function(){
    $("table.user tr").filter(':odd').addClass('alt');
	
});
</script>